//有且仅有一个人的入度是n-1，出度是0
using PII=pair<int, int>;
#define out first
#define in second
class Solution {
public:
    
    int findJudge(int n, vector<vector<int>>& trust) {
        vector<int> out(n+1, 0);
        vector<PII> du(n+1, {0, 0});
        for(auto edge:trust) //u believe v
        {
            int u=edge[0], v=edge[1];
            du[u].out++; 
            du[v].in++;
        }
        int ans=-1;
        for(int i=1; i<=n; i++)
        {
            auto d=du[i];
            if(d.in==n-1&&d.out==0) 
            {
                if(ans==-1) ans=i;
                else return-1;
            }
        }
        return ans;
    }
};